package com.example.myapplication.adapter

import android.content.Context
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.bumptech.glide.load.MultiTransformation
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.QuickViewHolder
import com.example.myapplication.entity.PopularScienceEntity
import com.example.total.R

class PopularScienceAdapter: BaseQuickAdapter<PopularScienceEntity, QuickViewHolder>()   {
    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: PopularScienceEntity?) {
        item?.run {
            Glide.with(context)
                .setDefaultRequestOptions(
                    RequestOptions()
                        .transform(MultiTransformation(CenterCrop(), RoundedCorners(10))))
                .load(cover)
                .into(holder.getView(R.id.cover))
            holder.setText(R.id.name,name).setText(R.id.describe,describe)
        }
    }

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): QuickViewHolder {
        return QuickViewHolder(R.layout.popular_science_item, parent)

    }


}